package com.zsrt.hechao.user.service.impl;

import java.util.Date;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.zsrt.hechao.user.dao.UserDao;
import com.zsrt.hechao.user.entity.UserEntity;
import com.zsrt.hechao.user.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Resource
	private UserDao dao;

	public int login(UserEntity entity) {

		return dao.login(entity);
	}

	/**
	 * 用户注册
	 * 
	 * @param entity
	 *            用户实体
	 * @return 1代表成功 0代表失败
	 */
	public int register(UserEntity entity) {
		// 1 先判断手机号码是否重复

		int ck = dao.checkPhone(entity);

		if (ck == 1) {
			return 0;
		}

		// 2 如果手机号码不重复 直接插入

		Date date = new Date();

		entity.setRegisterTime(date);

		int counter = dao.add(entity);
		return counter;
	}

	public UserEntity findById(Integer id) {
		
		return dao.selectByPrimaryKey(id);
	}

}
